﻿/************************************************************************
* Copyright (c) 2018 All Rights Reserved.
*命名空间：Wx.Standard
*文件名： WeChat
*创建人： kingling
*创建时间：2018/6/29 18:08:00
*描述
*=======================================================================
*修改标记
*修改时间：2018/6/29 18:08:00
*修改人：kingling
*描述：
************************************************************************/

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Wx.Standard.IService;
using Wx.Standard.Options;
using Wx.Standard.Service;

namespace Wx.Standard
{
    public sealed class WxApi
    {
        IGetMessage weChatGetMessage = null;
        ISendModelMessage weChatSendMessage = null;
        IWeb weChatWeb = null;
        /// <summary>
        /// 商家微信ID
        /// </summary>
        public string ownId;
        /// <summary>
        /// 用户Openid
        /// </summary>
        public string openId;
        public ApiOption apiOption;
        public HttpContext context;
        public WxApi(IHttpContextAccessor httpContextAccessor, IOptions<ApiOption> options)
        {
            this.apiOption = options.Value;
            context = httpContextAccessor.HttpContext;
        }
        private WxApi()
        {
        }
        /// <summary>
        /// 接收微信消息
        /// </summary>
        public IGetMessage Message
        {
            get
            {
                if (weChatGetMessage == null)
                {
                    this.weChatGetMessage = new GetMessage(this);
                }
                return weChatGetMessage;
            }
        }
        /// <summary>
        /// 发送消息
        /// </summary>
        public ISendModelMessage Send
        {
            get
            {
                if (weChatSendMessage == null)
                {
                    this.weChatSendMessage = new SendModelMessage(this);
                }
                return weChatSendMessage;
            }
        }
        /// <summary>
        /// 网页授权
        /// </summary>
        public IWeb Web
        {
            get
            {
                if (weChatWeb == null)
                {
                    this.weChatWeb = new Web(this);
                }
                return weChatWeb;
            }
        }
    }
}
